package com.explorati.design_pattern.behavior.iterator.example;

public class ConcreteIterator implements Iterator {

	private ConcreteAggregate agg;
	private int index = 0;
	public int size = 0;

	public ConcreteIterator(ConcreteAggregate agg) {
		this.agg = agg;
		this.index = 0;
		this.size = agg.size();
	}

	@Override
	public Object next() {
		if(index < size){
			return agg.getElement(index++);
		}else{
			return null;
		}
	}

	@Override
	public boolean hasNext() {
		return index < size;
	}

}
